﻿using CoffeeShop.DAO;
using CoffeeShop.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CoffeeShop.BIZ
{
    public class AreaBiz
    {
        private AreaDao _areaDao = new AreaDao();

        /// <summary>
        /// Convert value to Area object
        /// </summary>
        /// <param name="areaId">AreaId property</param>
        /// <param name="areaName">AreaName property</param>
        /// <param name="officeId">OfficeId property</param>
        /// <param name="isDeleted">IsDelete property</param>
        /// <returns>Area object</returns>
        public Area ConvertToObject(string areaName, int officeId, int areaId = 0, bool isDeleted = false)
        {
            Area area = new Area();
            area.AreaId = areaId;
            area.AreaName = areaName;
            area.OfficeId = officeId;
            area.IsDelete = isDeleted;
            return area;
        }

        /// <summary>
        /// Get all areas in DB
        /// </summary>
        /// <returns></returns>
        public List<Area> GetListAreas()
        {
            return _areaDao.GetListAreas();
        }

        /// <summary>
        /// Get an area by AreaId
        /// </summary>
        /// <param name="areaId">Area object</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public Area GetAreaById(int areaId)
        {
            return _areaDao.GetAreaById(areaId);
        }

        /// <summary>
        /// Get list areas based on OfficeId
        /// </summary>
        /// <param name="officeId">OfficeId</param>
        /// <returns>List of area</returns>
        public List<Area> GetListAreasByOfficeId(int officeId)
        {
            return _areaDao.GetListAreasByOfficeId(officeId);
        }

        /// <summary>
        /// Create an area
        /// </summary>
        /// <param name="areaId">Area object</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public bool CreateArea(Area area)
        {
            return _areaDao.CreateArea(area);
        }

        /// <summary>
        /// Update an area
        /// </summary>
        /// <param name="areaId">Area object</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public bool UpdateArea(Area area)
        {
            return _areaDao.UpdateArea(area);
        }

        /// <summary>
        /// Delete an area
        /// </summary>
        /// <param name="areaId">AreaId</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public bool DeleteArea(int areaId)
        {
            return _areaDao.DeleteArea(areaId);
        }

        /// <summary>
        /// Get an area by name and officeId
        /// </summary>
        /// <param name="areaName">Area Name</param>
        /// <param name="officeId">OfficeId</param>
        /// <returns></returns>
        public Area GetAreaByNameAnOfficeId(string areaName, int officeId)
        {
            return _areaDao.GetAreaByNameAndOfficeId(areaName, officeId);
        }

        /// <summary>
        /// Get an Office by Office's name
        /// </summary>
        /// <param name="officeName">Name of Office</param>
        /// <returns>True: Is Existed - False: Not Exist</returns>
        public bool IsExistArea(string areaName, int officeId)
        {
            Area area = new Area();
            area = _areaDao.GetAreaByNameAndOfficeId(areaName, officeId);
            if (area != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Check is exist an office which has the same name
        /// </summary>
        /// <param name="officeId"></param>
        /// <returns></returns>
        public bool IsExistedWhenUpdate(int officeId, string areaName, int areaId)
        {
            return _areaDao.IsExistedWhenUpdate(officeId, areaName, areaId);
        }
    }
}